package com.dbh.alg.datastructure.stack;

import org.apache.commons.math3.exception.MathIllegalNumberException;

/**
 * @author dongbanghui
 * @date 2025/5/22
 */
public class E01Leetcode20 {

    public boolean isValid(String s) {
        char[] charArr = s.toCharArray();
        Stack<Character> stack = new LinkedListStack<>();
        for (char c : charArr) {
           if (c == '(') {
               stack.push(')');
           } else if (c == '[') {
                stack.push(']');
            } else if (c == '{') {
                stack.push('}');
            } else {
               if (!stack.isEmpty()) {
                   Character pop = stack.pop();
                     if (pop != c) {
                          return false;
                     }
               } else {
                   return false;
               }
           }

        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        E01Leetcode20 e01Leetcode20 = new E01Leetcode20();
        System.out.println(e01Leetcode20.isValid("]"));
    }
}
